/* 
 * File:   Rational.h
 * Author: griver
 *
 * Created on 21 Октябрь 2011 г., 14:21
 */

#ifndef RATIONAL_H
#define	RATIONAL_H
#include <algorithm>
#include <iostream>

class Rational
{
private:
 //поля класса 
    int x;              // числитель
    int y;              // знаменатель

public:
// конструктор
    Rational(int x, int y);     // дробная
    Rational(int x);            // целое число
    Rational(Rational const & r);
public:
// операторы
    Rational & operator=( Rational const & r );
    Rational & operator+=( Rational const & r );
    Rational & operator-=( Rational const & r );
    Rational & operator/=( Rational const & r );
    Rational & operator*=( Rational const & r );
    operator double() const;
    Rational const operator-() const;
    Rational& operator++();
    Rational operator++(int);
    Rational& operator--();
    Rational operator--(int);

private:
// внутренние методы
    void swap( Rational & a );
    void correct_sign();
    int gcd(int a, int b);
    void correct();
    
public:
    void print() const;
    friend bool operator<  (const Rational& a, const Rational& b);
};

// Нум
Rational operator+ (const Rational& a, const Rational& b);
Rational operator- (const Rational& a, const Rational& b);
Rational operator* (const Rational& a, const Rational& b);
Rational operator/ (const Rational& a, const Rational& b);

bool operator== (const Rational& a, const Rational& b);
bool operator!= (const Rational& a, const Rational& b);
bool operator<= (const Rational& a, const Rational& b);
bool operator>= (const Rational& a, const Rational& b);
bool operator>  (const Rational& a, const Rational& b);

#endif	/* RATIONAL_H */

